package com.hundsun.yr.universal.p2p.ui.activity.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.base.BaseAppCompatActivity;
import com.hundsun.yr.universal.library.utils.ThemeUtils;
import com.hundsun.yr.universal.p2p.HsApplication;
import com.hundsun.yr.universal.p2p.view.base.BaseView;

public abstract class BaseScrollActivity extends BaseAppCompatActivity implements BaseView{

	protected Toolbar mToolbar;
    /**
     * ScrollView中LinearLayout 容器
     */
    private LinearLayout linear_container;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (isApplyKitKatTranslucency()) {
			setSystemBarTintDrawable(getResources().getDrawable(ThemeUtils.getStatusbar_color()));
		}
	}
	
	public void setContentView(int layoutResID) {
		super.setContentView(layoutResID);
		
		if(isScrollContainer()){
    		linear_container = (LinearLayout)findViewById(R.id.linear_container);
    		((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(getContentViewLayoutID(), linear_container);
    	}else{
    		setContentView(getContentViewLayoutID());
    	}
		mToolbar = (Toolbar)findViewById(R.id.common_toolbar);
		if (null != mToolbar) {
			setSupportActionBar(mToolbar);
			getSupportActionBar().setHomeButtonEnabled(true);
			getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}
	
	@Override
	protected int configTheme() {
		// TODO Auto-generated method stub
//		int theme = ThemeUtils.themeArr[ThemeUtils.getThemeColorIndex()][0];
		int theme=ThemeUtils.getTheme();
		if (theme > 0)
			return theme;
		return super.configTheme();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
//	        MobclickAgent.onResume(this);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
//	        MobclickAgent.onPause(this);
	}
	
	protected HsApplication getBaseApplication() {
		return (HsApplication) getApplication();
	}
	
	@Override
	public void showError(String msg,OnClickListener onClickListener) {
		toggleShowError(true, msg, onClickListener);
	}
	
	
	@Override
	public void showNetError(OnClickListener onClickListener) {
		// TODO Auto-generated method stub
		toggleNetworkError(true, onClickListener);
	}
	
	@Override
	public void showLoading(String msg) {
		toggleShowLoading(true, null);
	}
	
	@Override
	public void hideLoading() {
		toggleShowLoading(false, null);
	}
	/**
	 * 是否改变状态栏背景
	 * @return
	 */
	protected abstract boolean isApplyKitKatTranslucency();
	
	/**
	 * 是否在ScrollView 容器内
	 * @return
	 */
	protected abstract boolean isScrollContainer();

}
